package com.ruoyi.web;

import ai.dify.javaclient.ChatClient;
import ai.dify.javaclient.CompletionClient;
import ai.dify.javaclient.DifyClient;
import okhttp3.Response;

public class WorkflowRun {
    public static void main(String[] args) throws Exception {
        try {
            String user = "zxy";
            String inputs = """
                    {
                      "inputs": {
                        "input_text": "fffffff",
                        "Multisentiment": "True",
                        "ddd": [
                          {
                            "type": "document",
                            "transfer_method": "local_file",
                            "url": "",
                            "upload_file_id": "dfea6395-f913-4baf-af61-98d26257049e"
                          }
                        ]
                      },
                      "response_mode": "streaming"
                    }
                    """;
            String query = "";
            boolean responseMode = true;
            String API_KEY = "app-elye5816ibqQVCwrmlRWchaP";


            // Create a completion client
            CompletionClient completionClient = new CompletionClient(API_KEY);
            Response completionResponse = completionClient.createCompletionMessage(inputs, query, user, responseMode);
            System.out.println(completionResponse.body().string());

            // Create a chat client
            ChatClient chatClient = new ChatClient(API_KEY);
            // Create a chat message
            Response chatResponse = chatClient.createChatMessage(inputs, query, user, true, null);
            System.out.println(chatResponse.body().string());

            // Fetch conversations
            chatClient.getConversations(user, null, 100, null);
            // Rename conversation
            String conversationId = "example-conversation-id";
            String name = "new-name";
            chatClient.renameConversation(conversationId, name, user);

            // And so on for other methods...

            DifyClient client = new DifyClient(API_KEY);
            // Fetch application parameters

            client.getApplicationParameters(user);

            // Provide feedback for a message
            String messageId = "your-message-id";
            String rating = "5";
            client.messageFeedback(messageId, rating, user);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
